﻿using System.Linq;
using CardPlay.Model.CardModel;
using CardPlay.Model.GameModel;
using CardPlay.Model.GameModel.Presentation;
using CardPlay.Model.Layout;
using CardPlay.Model.Primitives;

namespace CardPlay.DemoPack.Games.FourSeasonsVariants
{
    [Game("D9BDFBA7-C6C4-4B8E-BA93-3831FD0D8CDF", LevelOfDifficulty.Easy, LevelOfSkill.MostlyChance, DurationOfPlay.LessThan5Minutes, Family = FamilyName)]
    public class Simplicity : FourSeasons
    {
        public Simplicity()
        {
            TotalTableaus = 12;
            TableauBuildSequence = CardFaceSequence.AlternatingColorDescendingRank;
        }

        public override ILayoutSite CreatePresentation(IPresentationContext presentation)
        {
            var root = presentation.CreateRowLayout();

            var column1 = new UniformGridLayout { Columns = 1, Rows = 2 };
            root.Add(column1);

            column1.Add(presentation.CreatePileVisual(Foundation1, AugmentStyle(presentation, HorizontalAlignment.Left, VerticalAlignment.Top, presentation.Metrics.CardSize)));
            column1.Add(presentation.CreatePileVisual(Foundation2, AugmentStyle(presentation, HorizontalAlignment.Left, VerticalAlignment.Bottom, presentation.Metrics.CardSize)));

            root.Add(presentation.CreateMimimalSpacer());

            {
                var column2 = presentation.CreateColumnLayout();
                root.Add(column2);

                {
                    var stockWaste = presentation.CreateRowLayout();
                    column2.Add(stockWaste);

                    var stockStyle = StandardStyles.Stock;
                    stockStyle.EmptyCue = () => IsRedealPossible ? EmptyPileCue.Redeal : EmptyPileCue.NoRedeal;
                    stockStyle.MinimumSize = new Size(0, presentation.Metrics.CardSize.Height + presentation.Metrics.MinSpacingDown);

                    stockWaste.Add(presentation.CreatePileVisual(Stock, stockStyle));
                    stockWaste.Add(presentation.CreatePileVisual(Waste, StandardStyles.Waste));

                    stockWaste.HorizontalContentAlignment = HorizontalAlignment.Center;
                }

                var row1 = presentation.CreateRowLayout();
                presentation.AddPiles(row1, NamesOfTableaus.Take(6),
                    AugmentStyle(presentation, HorizontalAlignment.Center, VerticalAlignment.Top, presentation.Metrics.CardSize, false));

                var row2 = presentation.CreateRowLayout();
                presentation.AddPiles(row2, NamesOfTableaus.Skip(6),
                    AugmentStyle(presentation, HorizontalAlignment.Center, VerticalAlignment.Top, presentation.Metrics.CardSize, false));

                column2.Add(row1);
                column2.Add(presentation.CreateMimimalSpacer());
                column2.Add(row2);
            }

            root.Add(presentation.CreateMimimalSpacer());

            var column3 = new UniformGridLayout { Columns = 1, Rows = 2 };
            root.Add(column3);

            column3.Add(presentation.CreatePileVisual(Foundation3, AugmentStyle(presentation, HorizontalAlignment.Left, VerticalAlignment.Top, presentation.Metrics.CardSize)));
            column3.Add(presentation.CreatePileVisual(Foundation4, AugmentStyle(presentation, HorizontalAlignment.Left, VerticalAlignment.Bottom, presentation.Metrics.CardSize)));

            return root;
        }
    }
}